<template>
  <div class="header">
    <div class="content-wrapper">
      <div class="avatar">
        <img width="64" height="64" :src="seller.avatar" alt />
      </div>
      <div class="content">
        <div class="title">
          <span class="brand"></span>
          <span class="name">郑陈辰家常菜</span>
        </div>
        <div class="description">{{seller.description}}/{{seller.deliveryTime}}分钟送达</div>
        <div v-if="seller.supports" class="support">
          <span class="icon" :class="classMap[seller.supports[0].type]"></span>
          <span class="text">{{seller.supports[0].description}}</span>
        </div>
      </div>
      <div v-if="seller.supports" class="support-count" @click="showDetail">
        <span class="count">{{seller.supports.length}}个</span>
        <i class="icon-keyboard_arrow_right"></i>
      </div>
    </div>
    <!-- 公告部分 -->
    <div class="bulletin-wrapper" @click="showDetail">
      <span class="bulletin-title"></span>
      <span class="bulletin-text">{{seller.bulletin}}</span>
      <i class="icon-keyboard_arrow_right"></i>
    </div>
    <!-- 头部的背景阴影 -->
    <div class="background">
      <img :src="seller.avatar" width="100%" height="100%" alt />
    </div>
    <!-- 弹出层 -->
    <transition name="fade">
      <div v-show="detailShow" class="detail">
        <div class="detail-wrapper clearfix">
          <div class="detail-main">
            <h1 class="name">{{seller.name}}</h1>
            <!-- 五星评分 -->
            <div class="star-wrapper">
              <star :size="48" :score="seller.score"></star>
            </div>
            <!-- 优惠信息 -->
            <div class="title">
              <div class="line"></div>
              <div class="text">优惠信息</div>
              <div class="line"></div>
            </div>
            <!-- 根据classMap确定图标类名 -->
            <ul v-if="seller.supports" class="supports">
              <li class="support-item" v-for="(item,index) in seller.supports" :key="index">
                <span class="icon" :class="classMap[item.type]"></span>
                <span class="text">{{item.description}}</span>
              </li>
            </ul>
            <!-- 商家公告 -->
            <div class="title">
              <div class="line"></div>
              <div class="text">商家公告</div>
              <div class="line"></div>
            </div>
            <div class="bulletin">
              <p class="content">{{seller.bulletin}}</p>
            </div>
          </div>
        </div>
        <div class="detail-close" @click="detailClose">
          <i class="icon-close"></i>
        </div>
      </div>
    </transition>
  </div>
</template>
<script>
import star from "../star/star";
export default {
  name: "",
  props: {
    seller: Object
  },
  components: { star },
  data() {
    return {
      classMap: [],
      detailShow: false
    };
  },
  methods: {
    showDetail() {
      this.detailShow = true;
    },
    detailClose() {
      this.detailShow = false;
    }
  },
  created() {
    this.classMap = ["decrease", "discount", "special", "invoice", "guarantee"];
  }
};
</script>
<style lang='stylus' scoped>
.header {
  position: relative;
  background-color: rgba(7, 17, 27, 0.5);
  color: #fff;
  overflow: hidden;

  .content-wrapper {
    position: relative;
    display: flex;
    margin: 24px 12px 18px 24px;
    font-size: 0; // 清除avatar和content之间的缝隙

    .avatar {
      vertical-align: top;

      img {
        border-radius: 4px;
      }
    }

    .content {
      font-size: 12px;
      margin-left: 16px;

      .title {
        font-size: 16px;
        height: 18px;
        line-height: 18px;

        // 设置品牌店铺图片
        .brand {
          display: inline-block;
          width: 30px;
          height: 18px;
          background: url('./brand@3x.png');
          background-size: 100% 100%;
          background-repeat: no-repeat;
          vertical-align: top; // 文字垂直顶部对齐
        }

        // 店铺名
        .name {
          margin-left: 6px;
          font-weight: 700;
          height: 18px;
          line-height: 18px;
        }
      }

      // 配送、时间描述
      .description {
        margin: 8px 0 10px 0px;
        height: 12px;
        line-height: 12px;
      }

      // 在线满减
      .support {
        .icon {
          display: inline-block;
          width: 12px;
          height: 12px;
          margin-right: 4px;
          background-size: 100% 100%;
          background-repeat: no-repeat;

          &.decrease {
            vertical-align: top;
            background-image: url('./decrease_1@2x.png');
          }

          &.discount {
            vertical-align: top;
            background-image: url('./discount_1@2x.png');
          }

          &.guarantee {
            vertical-align: top;
            background-image: url('./guarantee_1@2x.png');
          }

          &.invoice {
            vertical-align: top;
            background-image: url('./invoice_1@2x.png');
          }

          &.special {
            vertical-align: top;
            background-image: url('./special_1@2x.png');
          }
        }

        .text {
          vertical-align: top;
          font-size: 12px;
          line-height: 10px;
        }
      }
    }

    // 在线满减后面的几个(椭圆)
    .support-count {
      display: flex;
      position: absolute;
      right: 12px;
      bottom: 0px;
      padding: 0 8px;
      height: 24px;
      line-height: 24px;
      border-radius: 14px;
      background: rgba(0, 0, 0, 0.2);
      text-align: center;

      .count {
        vertical-align: top;
        font-size: 14px;
      }

      // 右箭头
      .icon-keyboard_arrow_right {
        font-size: 12px;
        line-height: 24px;
        margin-left: 2px;
      }
    }
  }

  .bulletin-wrapper {
    position: relative;
    background: rgba(7, 17, 27, 0.2);
    height: 28px;
    line-height: 28px;
    padding: 0 22px 0 12px;
    white-space: nowrap; // 设置不换行
    text-overflow: ellipsis; // 文字超出省略号
    overflow: hidden; // 设置隐藏

    // 公告部分的图片
    .bulletin-title {
      display: inline-block;
      width: 22px;
      height: 12px;
      background: url('./bulletin@2x.png');
      background-size: 100% 100%;
      backgroud-repeat: no-repeat;
    }

    // 公告里的文字
    .bulletin-text {
      margin: 0 4px;
      font-size: 12px;
      vertical-align: top;
      color: white;
    }

    // 公告里的箭头
    .icon-keyboard_arrow_right {
      position: absolute;
      right: 12px;
      top: 10px;
      font-size: 12px;
    }
  }

  // 头部的背景
  .background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    filter: blur(10px); // 毛玻璃效果
  }

  // 点击公告后展开的详细信息
  .detail {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 101;
    width: 100%;
    height: 100%;
    overflow: auto; // 加滚动条
    background: rgba(7, 17, 27, 0.8);
    backdrop-filter: blur(8px)
    .detail-wrapper {
      overflow hidden // 清除浮动 已经加了clearfix
      width: 100%;
      min-height: 100%;

      .detail-main {
        margin-top: 64px;
        padding-bottom: 64px;

        .name {
          text-align: center;
          line-height: 16px;
          font-weight: 700;
          font-size: 16px;
        }

        // 五星评分
        .star-wrapper {
          text-align: center;
          margin-top: 18px;
          padding: 2px 0;
        }

        // 优惠信息
        .title {
          display: flex;
          width: 80%;
          margin: 28px auto 24px auto; // 父盒子占80%,左右auto平均分剩下的20%

          .line {
            flex: 1; // 两条横线平均分
            position: relative;
            top: -6px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.5);
          }

          .text {
            padding: 0 12px;
            font-size: 14px;
            font-weight: 700;
          }
        }

        // 优惠信息下的ul
        .supports {
          width: 80%;
          margin: 0 auto;

          // 每个li都有padding
          .support-item {
            padding: 0 12px;
            margin-bottom: 12px;
            font-size: 0;
            text-align: left;

            &:last-child {
              margin-bottom: 0;
            }

            // 每个li前面的图标
            .icon {
              display: inline-block;
              width: 16px;
              height: 16px;
              margin-right: 6px;
              background-size: 16px 16px;

              &.decrease {
                vertical-align: top;
                background-image: url('./decrease_2@3x.png');
              }

              &.discount {
                vertical-align: top;
                background-image: url('./discount_2@3x.png');
              }

              &.guarantee {
                vertical-align: top;
                background-image: url('./guarantee_2@3x.png');
              }

              &.invoice {
                vertical-align: top;
                background-image: url('./invoice_2@3x.png');
              }

              &.special {
                vertical-align: top;
                background-image: url('./special_2@3x.png');
              }
            }

            .text {
              font-size: 12px;
              line-height: 16px;
            }
          }
        }

        // 商家公告
        .bulletin {
          width: 80%;
          margin: 24px auto 24px auto;

          .content {
            padding: 0 12px;
            line-height: 24px;
            font-size: 12px;
            color: rgb(255, 255, 255);
            font-weight: 200;
          }
        }
      }
    }

    // 关闭图标样式
    .detail-close {
      position: relative;
      width: 32px;
      height: 32px;
      margin: -64px auto 0 auto;
      clear: both;
      font-size: 32px;
    }
  }

  .fade-enter-active, .fade-leave-active {
    opacity: 1;
    transition: opacity 0.8s linear;
  }

  .fade-enter, .fade-leave-to {
    opacity: 0;
  }
}
</style>
